package com.example.springbootdockerdemo.controller;

import com.example.springbootdockerdemo.annotation.Authorized;
import com.example.springbootdockerdemo.annotation.LogAop;
import com.example.springbootdockerdemo.annotation.PreventDuplication;
import com.example.springbootdockerdemo.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @ClassName Test
 * @Author Chengy
 * @Date 2021/11/17 16:24
 * @Version 1.0
 */

@Slf4j
@RestController
@RequestMapping("/")
@CrossOrigin
public class Test {


    @Autowired
    private UserService userService;

    @GetMapping("hello")
    public String test() {
        return "hello spring boot!!!" + "北京时间：" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
    }


    @RequestMapping
    public String index() {
        return "hello spring boot!!!" + "======北京时间：" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
    }


    @LogAop("去干饭接口")
    @PreventDuplication(expireSeconds = 8)
    @RequestMapping("eat")
    public Object eat(String eat) {
        log.info("请求参数：" + eat);
        return userService.eat(eat);
    }


    @LogAop("去干饭接口")
    @PreventDuplication(expireSeconds = 30)
    @PostMapping("test")
    public Object test(@RequestParam String eat, @RequestParam int a, @RequestBody Object data) {
        log.info("请求参数eat：" + eat);
        log.info("请求参数a：" + a);
        log.info("请求参数data：" + data);
        return userService.eat(eat);
    }

    @RequestMapping("out")
    public void out(String eat) {
        userService.out();
    }

    @Authorized
    @RequestMapping("shit")
    public Object shit(String eat) {
        userService.shit();
        return 1;
    }


    //
}
